import {defineConfig} from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'

import {magicURL} from './settings'

/**
 * 项目根目录
 * @description 结尾不带/
 */
const getRootPath = () => {
    return path.resolve(process.cwd())
}

/**
 * 项目src路径
 * @param srcName src目录名称（默认：“src”）
 * @description 结尾不带斜杆
 */
const getSrcPath = (srcName = 'src') => {
    return path.resolve(getRootPath(), srcName)
}


export default defineConfig({
    plugins: [vue()],
    base: '/newbing/',
    server: {
        proxy: {
            '/newbingAPI': {
                target:magicURL,
                changeOrigin: true,
                rewrite: (path) => path.replace(/^\/newbingAPI/, '')
            }
        }
    },
    resolve: {
        alias: {
            '@': getSrcPath(),
            '~': getRootPath()
        }
    },
    build:{
        outDir:'newbing'
    }
})
